<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuimini/css/public.css" media="all">

    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form id="userForm" class="layui-form" method="post" onsubmit="return false;">
<div class="layui-form layuimini-form" lay-filter="add_ncc">

    <div class="layui-form-item">
        <label class="layui-form-label required">名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name" lay-verify="required" lay-reqtext="资产用户名称不能为空" placeholder="请输入资产用户名称" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">系统用户</label>
        <div class="layui-input-block">
            <input type="text" name="username" id="username" lay-verify="required" lay-reqtext="资产组名称不能为空" placeholder="请输入系统用户名称" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">密码框</label>
        <div class="layui-input-block">
            <input type="password" name="password" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">资产列表</label>
        <div  id="members" name="members" class="layui-input-block"></div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">私钥</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入你的私钥" class="layui-textarea" name="privatekey"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">公钥</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入你的私钥" class="layui-textarea" name="pubkey"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入你的私钥" class="layui-textarea" name="info"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label"></label>
       <button class="layui-btn" lay-filter="ServerUserAdd" type="submit" lay-submit >立即提交</button>
    </div>

</div>
</form>

<script src="/static/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/static/layui/sm_select/xm-select.js"></script>
<script>
    layui.use(['form','laydate'],function () {
        window.form = layui.form
            ,window.$ = layui.$
            , laydate = layui.laydate;

        form.render();
        //日期
        laydate.render({
            elem: '#date'
        });

        //监听提交
        form.on('submit(ServerUserAdd)', function (data) {
            //发异步，把数据提交给php
            var name = data.field.name;
            var username = data.field.username;
            var password = data.field.password;
            var members = data.field.members;
            var privatekey = data.field.privatekey;
            var pubkey = data.field.pubkey;
            var info = data.field.info;

            //alert(JSON.stringify(data));

            $.ajax({
                type: 'post',
                url: "/resources/serveruser/create/",
                data: {name: name,username:username,
                       password: password,members:members,
                       privatekey: privatekey,pubkey:pubkey,
                       info: info
                        },
                success: function (res) {
                    if (res.status == 0) {
                        layer.alert(res.msg, {icon: 6}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                           //刷新页面
                            parent.location.reload();
                        });
                         //parent.layer.reload();

                    } else {
                        layer.alert(res.msg, {icon: 5}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            //刷新页面
                            parent.location.reload();
                        });
                    }
                }
            });
            return false;
        });
    });


    var demo1 = xmSelect.render({
                el: '#members',
                name: 'members',
                filterable: true,
                data: []
            })

    var test = {
        method1: function (data)
        {
            demo1.update({data:data});

        },
        method2: function () {
            return demo1.getValue();
        }

    }
    

</script>
</body>
</html>